import os
# import shutil
import cv2
# def my_same_file_diff_checker(*args, **kwargs):
#     return False
#
# shutil._samefile = my_same_file_diff_checker
# path = r"C:\Users\kingsha\Desktop\123"
# os.chdir(path)
# new_folder = "photo"
# if not os.path.exists(new_folder):
#     os.makedirs(new_folder)
#     print("Folder created")
# else:
#     print("Folder already exists")
# new_path = os.path.join(path, new_folder)
# files_list = []
# for root, dirs, files in os.walk(path):
#     for file in files:
#         if os.path.splitext(file)[1] == '.jpg':
#             files_list.append(os.path.join(root, file))
# for cur_file in files_list:
#     shutil.copy(cur_file, new_path)

path = r"C:\Users\kingsha\Desktop\123"
os.chdir(path)
new_folder = "photo"
if not os.path.exists(new_folder):
    os.makedirs(new_folder)
new_path = os.path.join(path, new_folder)
img_list = [os.path.join(nm) for nm in os.listdir(path) if nm[-3:] in ['jpg', 'png', 'gif']]
for i in img_list:
    image = cv2.imread(os.path.join(path, i))
    cv2.imwrite(os.path.join(new_path, os.path.basename(i)), image)